package com.atguigu.gmall.weball.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.search.SearchFeignClient;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @Author:lyd
 * @Date:2023/8/27 10:12
 * @Version:1.0
 * @Description
 **/
@Controller
public class SearchController {
    @Autowired
    SearchFeignClient searchFeignClient;

    /**
     * 前端发送过来的请求参数
     * list.html?category3Id=61&trademark=2:华为&props=23:256G:机身存储&props=24:6寸:屏幕尺寸&props=33:12G:机身内存&order=1:asc&pageNo=2
     *
     * @return
     */
    @GetMapping("/list.html")
    public String searchPage(SearchParamVo paramVo, Model model) {
        //远程调用检索服务，把页面需要的结果数据封装在result里面
        Result<SearchResultVo> result = searchFeignClient.search(paramVo);
        SearchResultVo data = result.getData();
        //页面查询用的所有的检索参数
        model.addAttribute("searchParam", data.getSearchParam());

        //---面包屑都是用来回显数据时使用的
        //品牌面包屑
        model.addAttribute("trademarkParam", data.getTrademarkParam());
        //平台属性面包屑
        model.addAttribute("propsParamList",data.getPropsParamList());

        //---二次检索区
        //品牌列表
        model.addAttribute("trademarkList",data.getTrademarkList());
        //符合当前检索条件的所有商品的属性列表
        model.addAttribute("attrsList", data.getAttrsList());

        //--商品数据区，展示检索到的所有商品
        model.addAttribute("goodsList", data.getGoodsList());

        //---排序、分页信息区
        model.addAttribute("orderMap", data.getOrderMap());
        model.addAttribute("pageNo", data.getPageNo());
        model.addAttribute("totalPages", data.getTotalPages());
        model.addAttribute("urlParam", data.getUrlParam());

        return "list/index";
    }
}
